const Joi = require('joi')
const expressJoi = require('@escook/express-joi')

// 用户注册验证
const registerSchema = {
	body: {
		username: Joi.string().alphanum().min(3).max(30).required(),
		password: Joi.string().pattern(new RegExp('^[a-zA-Z0-9]{6,30}$')).required(),
		email: Joi.string().email().required()
	}
}

// 用户登录验证
const loginSchema = {
	body: {
		username: Joi.string().required(),
		password: Joi.string().required()
	}
}

// 用户更新验证
const updateSchema = {
	body: {
		avatar: Joi.string().optional(),
		email: Joi.string().email().optional(),
		password: Joi.string().pattern(new RegExp('^[a-zA-Z0-9]{6,30}$')).optional()
	}
}

module.exports = {
	validateRegister: expressJoi(registerSchema),
	validateLogin: expressJoi(loginSchema),
	validateUpdate: expressJoi(updateSchema)
}
